package com.architecture.core.entity;

import org.hibernate.annotations.NaturalId;

import javax.persistence.*;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * LoginAction: Administrator
 * Date: 12-4-18
 * Time: 下午4:39
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "CORE_PERMISSION_ROLE")
public class PermissionRole extends BaseEntity {

    @NaturalId
    @Column(name = "ROLE_NAME")
    private String name;

    @ManyToOne(fetch = FetchType.EAGER, targetEntity = PermissionRole.class, cascade = CascadeType.ALL)
    private PermissionRole permissionRole;

//    @ManyToMany(fetch = FetchType.LAZY, targetEntity = PermissionRole.class, cascade = CascadeType.ALL, mappedBy = "permissionRoleList")
//    private List<PermissionRole> permissionRoleRevertList;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "permissionRole",targetEntity = PermissionRole.class, cascade = CascadeType.ALL)
    private List<PermissionRole> permissionRoleList;

    @ManyToMany(fetch = FetchType.LAZY, targetEntity = Permission.class, cascade = CascadeType.ALL)
    @JoinTable(name = "EX_PERMISSION_ROLE_PERMISSION", joinColumns = {@JoinColumn(name = "PERMISSION_ROLE_ID")}, inverseJoinColumns = {@JoinColumn(name = "PERMISSION_ID")})
    private List<Permission> permissionList;

//    @ManyToMany(fetch = FetchType.LAZY,targetEntity = Category.class,cascade = CascadeType.ALL,mappedBy = "permissionRoleList")
//    private List<Category> permissionTypeList;

    @ManyToOne(fetch = FetchType.EAGER, targetEntity = Category.class, cascade = CascadeType.ALL)
    @JoinColumn(name = "CATEGORY_ID")
    private Category category;


    public List<Permission> getPermissionList() {
        return permissionList;
    }

    public void setPermissionList(List<Permission> permissionList) {
        this.permissionList = permissionList;
    }

    public List<PermissionRole> getPermissionRoleList() {
        return permissionRoleList;
    }

    public void setPermissionRoleList(List<PermissionRole> permissionRoleList) {
        this.permissionRoleList = permissionRoleList;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

//    public List<PermissionRole> getPermissionRoleRevertList() {
//        return permissionRoleRevertList;
//    }
//
//    public void setPermissionRoleRevertList(List<PermissionRole> permissionRoleRevertList) {
//        this.permissionRoleRevertList = permissionRoleRevertList;
//    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public PermissionRole getPermissionRole() {
        return permissionRole;
    }

    public void setPermissionRole(PermissionRole permissionRole) {
        this.permissionRole = permissionRole;
    }
}
